<?php
/**
  * Musashi - A project manager for music groups and bands
  * Copyright (C) 2010 Daniel Torres
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */

/**
 *  This view shows a data entry/edit form for clothing
 *  
 *  @author Daniel Torres
 *  @package Musashi
 */

// Make sure we have access to this page
defined('_JEXEC') or die ('Restricted access. Sorry');

// We'll need all equipment type entries. Query them here
$model =& $this->getModel();
$types = $model->getRecordsForSection('clothingtype','id,name');

// Don't proceed unless we have some clothing types
if( $types == null )
{
    ?>    
    <script language="javascript" type="text/javascript">
    <!--
    function submitbutton(pressbutton)
    {
        var form = document.adminForm;
    
        // If we're just canceling, allow it to happen
        if(pressbutton=='cancel')
        {
            submitform(pressbutton);
            return;
        }
    
        alert("Sorry, define some clothing types first");
        return;
    }
    //-->
    </script>

    <form action="index.php" method="post" name="adminForm" id="adminForm">
        <h4>Sorry, no clothing types are defined yet. To add clothing, you must have at least one clothing type</h4>
        <input type="hidden" name="option" value="com_musashi" />
        <input type="hidden" name="task" value="" />
        <input type="hidden" name="controller" value="catalog" />
        <input type="hidden" name="id" value="<?php echo $this->record->id; ?>" />
        <input type="hidden" name="sectn" value="<?php echo $this->viewName; ?>" />
    </form>
    <?php
}
else
{
    // Prepare an array with all types
    $typeCount = count( $types );
    $typesCB   = array();
        
    for( $i = 0; $i < $typeCount; $i++ )
    {
        $row =& $types[$i];
        $typesCB[] = JHTML::_('select.option', $row->id, $row->name );
        
    }
    
    // Go on with the page
    ?>
    <script language="javascript" type="text/javascript">
    <!--
    function submitbutton(pressbutton)
    {
        var form = document.adminForm;
    
        // If we're just canceling, allow it to happen
        if(pressbutton=='cancel')
        {
            submitform(pressbutton);
            return;
        }
    
        // Make sure the name field is not empty
        if(form.name.value == "")
        {
            alert("You must supply a name for this piece 'o clothing");
            return;
        }
    
        submitform(pressbutton);    
    }
    //-->
    </script>
    <form action="index.php" method="post" name="adminForm" id="adminForm" >
        <fieldset class="adminform" >
            <legend>Clothing Details</legend>
            <table class="admintable">
                <tr>
                    <td width="100" align="right" class="key">
                        Name:
                    </td>
                    <td>
                        <input class="text_area" type="text" name="name" id="name" size="25" maxlength="25"
                               value="<?php echo $this->record->name; ?>" />
                    </td>
                </tr>
                <tr>
                    <td width="100" align="right" class="key">
                        Type:
                    </td>
                    <td>
                        <?php
                        echo JHTML::_('select.genericlist', $typesCB, 'clothingType', null, 'value', 'text', $this->record->clothingType);
                        ?>
                    </td>
                </tr>
                <tr>
                    <td width="100" align="right" class="key">
                        Colour:
                    </td>
                    <td>
                        <input class="text_area" type="text" name="colour" id="colour" size="25" maxlength="25"
                               value="<?php echo $this->record->colour; ?>" />
                    </td>
                </tr>
                <tr>
                    <td width="100" align="right" class="key">
                        Size:
                    </td>
                    <td>
                        <input class="text_area" type="text" name="size" id="size" size="10" maxlength="10"
                               value="<?php echo $this->record->size; ?>" />
                    </td>
                </tr>
        </table>
    </fieldset>
    <input type="hidden" name="option" value="com_musashi" />
    <input type="hidden" name="task" value="" />
    <input type="hidden" name="controller" value="catalog" />
    <input type="hidden" name="id" value="<?php echo $this->record->id; ?>" />
    <input type="hidden" name="sectn" value="<?php echo $this->viewName; ?>" />
</form>
    
    
    
<?php    
}

?>
